﻿<h1>CHECK DEMO CODE IN: \Cms_Data\Sites\SampleSite\Templates\Views\Article.List</h1>
<h2>Custom Test....CRUD Test.... Subscriber Test.....</h2>
<div style="background:green; color:white; height:100px;">
    @KoobooUtility.GetCustomField("TitleSuffix")
   <br />
    @KoobooUtility.GetViewParameterValue("Test1").AsLocalDateTime()
    <br />
    @KoobooUtility.GetViewParameterValue("Test2")
    <br />
    @MenuHelper.Current().CustomFields["Pixel"]
</div>
@{
    var list = BizContext.Current.ArticleBiz.GetListOrdered();
    var test1 = list.FirstOrDefault();
    test1.Title = " Change " + DateTime.Now;
    BizContext.Current.ArticleBiz.Update(test1);
    test1.___EnableVersion___ = false;
    BizContext.Current.ArticleBiz.Update(test1.UUID, Article.KEY.Title, test1.Title + " ...No Verstion..Again");
    //BizContext.Current.ArticleBiz.Add(test1);
    // BizContext.Current.ArticleBiz.Delete(test1.UUID);


    //Kooboo.CMS.Content.Models.Repository.Current.ExecuteQuery         
}

@foreach (var item in list)
{
<div class="block" @ViewHelper.EditItemAttributes(item)>
    <h4 class="title"><a href='@Url.FrontUrl().PageUrl("Articles/Detail", new { UserKey = item.UserKey })'@ViewHelper.Edit(item, "Title") >@item.Title</a></h4>
    <span class="date">@item.UtcCreationDate.AsLocalDateTime().ToString("yyyy-MM-dd")</span>
    <p @ViewHelper.Edit(item, "Summary")>@Html.Raw(item.Summary)</p>
    <a class="comment" href="@Url.FrontUrl().PageUrl("Articles/Detail", new { UserKey = item.UserKey })#comments">@(((Kooboo.CMS.Content.Models.TextContent)item).Children("Comment").Count()) Comments</a>
</div>
}

<h2>Pagination test.... MapTo Test.... GetQueryString Test....</h2>
<div style="border:2px solid green; color:green;">
@{
    var pageList = BizContext.Current.ArticleBiz.Query().ToPageList(KoobooUtility.GetAllQueryString("page", "1").AsInt(), 2);
    var pageOption = new PagerOptions
    {
        NextPageText = "Next »",
        PrevPageText = "« Previous",
        CssClass = "pagination",
        CurrentPagerItemWrapperFormatString = "<span class=\"current\">{0}</span>",
        NavigationPagerItemWrapperFormatString = "<span class=\"pagenavigation\">{0}</span>"
    };
}
@foreach (var article in pageList)
{
    Article item = article.MapTo<Article>();
<div class="block" @ViewHelper.EditItemAttributes(item)>
    <h4 class="title"><a href='@Url.FrontUrl().PageUrl("Articles/Detail", new { UserKey = item.UserKey })'@ViewHelper.Edit(item, "Title") >@item.Title</a></h4>
    <span class="date">@ViewHelper.DateTimeToString(item.UtcCreationDate, "yyyy-MM-dd")</span>
    <p @ViewHelper.Edit(item, "Summary")>@Html.Raw(item.Summary)</p>
    <a class="comment" href="@Url.FrontUrl().PageUrl("Articles/Detail", new { UserKey = item.UserKey })#comments">@(((Kooboo.CMS.Content.Models.TextContent)item).Children("Comment").Count()) Comments</a>
</div>
}
@Html.FrontHtml().Pager(pageList, pageOption)
    </div>

@{
    var latestSixMonths = BizContext.Current.ArticleBiz.Query().WhereGreaterThan(KB.KEY.TextContents.UtcCreationDate, DateTime.UtcNow.AddMonths(-6)).MapTo<Article>();
}
<div style="border:2px solid red; color:red;">
@foreach (var item in latestSixMonths)
{
<div class="block" @ViewHelper.EditItemAttributes(item)>
    <h4 class="title"><a href='@Url.FrontUrl().PageUrl("Articles/Detail", new { UserKey = item.UserKey })'@ViewHelper.Edit(item, "Title") >@item.Title</a></h4>
    <span class="date">@ViewHelper.DateTimeToString(item.UtcCreationDate, "yyyy-MM-dd")</span>
    <p @ViewHelper.Edit(item, "Summary")>@Html.Raw(item.Summary)</p>
    <a class="comment" href="@Url.FrontUrl().PageUrl("Articles/Detail", new { UserKey = item.UserKey })#comments">@(((Kooboo.CMS.Content.Models.TextContent)item).Children("Comment").Count()) Comments</a>
</div>
}
    </div>
<div>
    <div style="width:200px; height:100px; border:2px solid blue;">
    @TestKoobooHelper.RenderEmail()
         @Html.Raw(TestKoobooHelper.RenderEmail())
        </div>

     <form style="width:100%; min-height:200px; border:2px solid orange;" id="knockoutTest">
   <input type="text" value="2" autocomplete="off"/>
         <div data-bind="foreach: list">
             <span data-bind="text:$index()+1"></span>
             <input type="text" data-bind="value:Title" />
             <strong data-bind="text:Sequence"></strong>
             <br />
         </div>
         <button type="submit">Submit</button>
        </form>
    <script type="text/javascript">
        $(function () {
            var $knockoutTest = $('#knockoutTest');
            var ItemModel = function (setting) {
                var self = this;
                var defaultSetting = {
                    Title: '',
                    Sequence: 0
                };
                setting = $.extend(defaultSetting, setting);
                self.Title = ko.observable(setting.Title);
                self.Sequence = setting.Sequence;
            };
            var listModel = function (list) {
                var self = this;
                self.list = ko.observableArray(list || []);
            };
            var vm = new listModel();
            ko.applyBindings(vm, $knockoutTest[0]);
            $knockoutTest.find(':text').change(function () {
                var $this = $(this);
                $.getJSON('/_Test/Test/KnockOut', { 'take': parseInt($this.val()) }, function (data) {
                    vm.list.removeAll();
                    $.each(data, function () {
                        vm.list.push(this);
                    });
                });
            }).change();
            $knockoutTest.submit(function () {
                alert('see browser\'s console: ' + vm.list()[0].Title);
                if (console) {
                    console.log(vm.list());
                }
                return false;
            });
        });

    </script>
</div>